

void Print()
{
    std::cout << "我是子进程：pid" << getpid() << "我是打印任务" << std::endl;
}

void Download()
{
    std::cout << "我是子进程：pid" << getpid() << "我是下载任务" << std::endl;
}

void sql()
{
    std::cout <<  "我是子进程：pid" << getpid() << "我是数据库任务" << std::endl;
}

class Task
{
public:
    Task()
    {
        srand(time(nullptr));
        _tasks.emplace_back(Print);
        _tasks.emplace_back(Download);
        _tasks.emplace_back(sql);
    }
    int DispatchTask()
    {
        int size = _tasks.size();
        return rand() % size;
    }
    void Execute(int i)//执行任务
    {
        _tasks[i]();
        //sleep(1);
    }
    ~Task()
    {

    }
private:
    std::vector<work_t> _tasks;

};

Task gtask;
